package com.globaldom.utils;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class Mailer {

	public boolean sendEmail(String from, String displayFrom, String toAddress, String subject, String body) {
		try {
			Properties props = new Properties();
			Session session = Session.getDefaultInstance(props, null);
			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress(from, displayFrom));
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
			message.setSubject(subject);
			Multipart multipart = new MimeMultipart();
			MimeBodyPart textPart = new MimeBodyPart();
			textPart.setContent(body, "text/html");
			multipart.addBodyPart(textPart);
			message.setContent(multipart);
			Transport.send(message);
			return true;
		} catch (AddressException e) {
			return false;

		} catch (MessagingException e) {
			return false;
		} catch (Exception ex) {
			return false;
		}
	}

}
